import axios from 'axios'

const request = axios.create({
   // baseURL:'http://localhost:9090/',
   baseURL:'http://192.168.61.163:9090/',
    timeout:5000,
    headers:{
        'token':localStorage.getItem("token")
    }
})

request.interceptors.request.use(config =>{
    config.headers['Content-Type']='application/json;charset=utf-8';
    //config.headers['token']=user.token; //请求头
    return config
},error =>{
    return Promise.reject(error)
});

request.interceptors.response.use(
    response=>{
        let res = response.data;
        if(typeof res === 'string'){
            res = res ? JSON.parse(res):res        }
        return res;
    },
    error=> {
        console.log('err'+error)
        return Promise.reject(error)
    }
)

export default request